// page_two/qipqiz/qipqiz.js
let app = getApp()
let yuming = app.globalData.yuming
var shuzong = []
var shu = []
const request = require('../../config/request');
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    yuming: yuming,
    heights: "",
    title: "气瓶气站",
    huan: ['设备报备', '维保记录'],
    currtab: 0,
    page: 1,
    // wbList: [{
    //     jcdate: '2022-06-10',
    //     sbxh: '气瓶',
    //     jcsx: '气瓶',
    //     result: '正常',
    //     images: [yuming + 'static/applet/images/index/shanchu.png']
    //   },
    //   {
    //     jcdate: '2022-06-09',
    //     sbxh: '加油器具',
    //     jcsx: '防雷检测',
    //     result: '正常',
    //     images: [yuming + 'static/applet/images/index/shanchu.png', yuming + 'static/applet/images/index/shanchu.png']
    //   }
    // ],
    // sbList: [{
    //     danwei: '中海石油',
    //     models: '气瓶',
    //     sctime: '2020-01-19',
    //     bftime: '2023-01-20',
    //     changshang: yuming + 'static/applet/images/index/shanchu.png',
    //     xuke: yuming + 'static/applet/images/index/shanchu.png',
    //     jiancha: yuming + 'static/applet/images/index/shanchu.png',
    //     hege: yuming + 'static/applet/images/index/shanchu.png',
    //     caigou: yuming + 'static/applet/images/index/shanchu.png',
    //   },
    // ],
    List: [],
    gongwu: false,
  },
  // tab切换
  qies(e) {
    shuzong = [];
    shu = [];
    var index = e.currentTarget.dataset.currtab
    this.setData({
      currtab: index,
      page: 1,
      gongwu: false,
    })
    this.getList();
  },
  // 维保查看更多
  lookmore() {
    shuzong = this.data.List;
    this.setData({
      page: (this.data.page) + 1
    })
    this.getList();
  },
  // 放大
  fangda(e) {
    var img = e.currentTarget.dataset.img
    wx.previewImage({
      urls: [img]
    })
  },
  getList() {
    let that = this;
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    let u = '';
    if (that.data.currtab == 0) {
      u = 'Gasstation/gasstation_list'
    } else {
      u = 'Gasstation/gasstation_weibao_list'
    }
    this.myRequest(yuming + u, {
      shopId: wx.getStorageSync('shopId'),
      page: that.data.page
    }, 'POST').then(res => {
      wx.hideLoading();
      if (res.data.code == 200) {
        shu = res.data.data
        if (this.data.page != 1) {
          if (shu.length != 10) {
            wx.showToast({
              title: '没有更多数据了~',
              icon: "none"
            })
            this.setData({
              gongwu: true
            })
          }
        }
        this.setData({
          List: shuzong.concat(shu)
        })
      }
    })
  },
  // 删除
  shan(e) {
    var id = e.currentTarget.dataset.id
    var that = this
    console.log(id);
    wx.showModal({
      title: '您确定要删除吗？',
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          console.log("确定")
          that.dele(id)
        } else {
          console.log("取消")
        }
      }
    })
  },
  // 删除接口
  dele(id) {
    let that = this
    var u = '';
    if (that.data.currtab == 0) {
      u = 'Gasstation/gasstation_del'
    } else {
      u = 'Gasstation/gasstation_weibao_del'
    }
    this.myRequest(yuming + u, {
      id
    }, "POST").then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        shuzong = [];
        shu = [];
        this.setData({
          page: 1,
          gongwu: false
        })
        this.getList();
      }
    })
  },
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  // 维保记录
  wbjia() {
    wx.navigateTo({
      url: '/page_two/qpqzaddweib/qpqzaddweib'
    })
  },
  // 设备报备
  bbjia() {
    wx.navigateTo({
      url: '/page_two/qpqzaddsheb/qpqzaddsheb'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    shuzong = [];
    shu = [];
    this.setData({
      page: 1,
      gongwu: false
    })
    this.getList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },
})